package ru.bytedog.oiot.counter.bot.controller.rest;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import ru.bytedog.oiot.counter.bot.dto.dashboard.ApiErrorResponse;
import ru.bytedog.oiot.counter.bot.exception.ServiceException;

@ControllerAdvice
public class ApiExceptionHandler extends ResponseEntityExceptionHandler {

    @ExceptionHandler({ ServiceException.class })
    public ResponseEntity<ApiErrorResponse> handleServiceException(ServiceException exception) {
        return new ResponseEntity<>( new ApiErrorResponse(exception), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
    }

}
